
import sys
import time
import datetime


def produce(queue):

    i = 0
    while True:

        if i<5:
            queue.append(i)
            yield i
            i = i+1
            #time.sleep(1)
        else:
            return

def customer(queue):

    p = produce(queue)
    while True:
        try:
            p.next()
            while len(queue) > 0:
               print queue.pop()
        except StopIteration, e:
            print "queue pop over."
            sys.exit(1)

queue = []
customer(queue)

